﻿using Microsoft.SqlServer.Management.Smo;

namespace NazTek.Utility.Extensions.SqlObject
{
    /// <summary>
    /// Extends SMO's DataType object.
    /// </summary>
    public static class DataTypeExtension
    {
        /// <summary>
        /// Adds a column to a specified table.
        /// </summary>
        /// <param name="dataType">The table to add a column to.</param>
        /// <param name="parent"></param>
        /// <param name="columnName"></param>
        /// <param name="isNullable"></param>
        /// <param name="defaultValue"></param>
        public static Column GetColumn(this DataType dataType, TableViewTableTypeBase parent, string columnName, bool isNullable = false,
            string defaultValue = "")
        {
            var column = new Column {Parent = parent, DataType = dataType, Name = columnName, Nullable = isNullable};
            column.AddDefaultConstraint().Text = defaultValue;
            return column;
        }
    }
}
